﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using University.Workshop.Business;

namespace University.Workshop.WebApp
{
    public partial class RegisterAuction : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }
            TxtBoxProductID.Text = Request["IdProduct"];
            LblProductName.Text = Request["NameProduct"];
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }
            else
            {
                string moneda="";
                if(RadioButtonBolivianos.Checked)
                {
                    moneda="Bolivianos";
                }
                if(RadioButtonDollars.Checked)
                {
                    moneda="Dollars";
                }
                try
                {
                    AuctionRegistrationManager.RegisterAuction(User.Identity.Name,TxtBoxAmount.Text, moneda, TxtBoxProductID.Text, Calendar1.SelectedDate, DropDownList1.SelectedIndex, DropDownList2.SelectedIndex);
                    Response.Redirect("AuctionRegistrationSuccess.aspx");
                }
                catch (Exception er)
                {
                    LblError.Visible = true;
                    LblError.Text = er.Message;
                }
            }
        }
    }
}